<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Description of dashboard
 *
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Cms extends MX_Controller {

	function cms() {
		parent :: __construct();
			
		$this->template
		->set_layout('default') // application/views/layouts/two_col.php
		->set_theme('admin'); // application/views/layouts/two_col.php
		
		$this->template->set_partial('nav_bar', 'layouts/nav_bar');
		$this->template->set_partial('side_menu', 'layouts/side_menu');
		$this->template->set_partial('footer','footer/footer');
		
		$this->load->model('admin_cms_model');
	}
	
	function index()
	{
		$data['content']['management'] = admin_cms_model::get_cms();
		$this->template->build('cms/cms_management',$data);
	}
	
	function get_cms() {
		
		$data['content']['management'] = admin_cms_model::get_cms();
		
		if ($this->input->post('cms')) {
			$this->form_validation->set_rules('cms', 'cms', 'required|xss_clean');
			$title = $this->input->post('cms');
			if ($this->form_validation->run()) {
				$sql="select * from cms where title='$title'";
				$query=$this->db->query($sql);
				$data['cms']['info']=$query->row();
				$data['cms_id']= $data['cms']['info']->id;
				$this->template->build('cms/cms_management', $data);
			}
		}
		else{
			$this->session->set_flashdata('message', 'Please Choose a cms');
			redirect('secure/cms');
		}
	
	}
	function update_cms() {
	
		if ($this->input->post('cms_update')) {
			$this->form_validation->set_rules('cmscontent', 'Description', 'required|xss_clean');
			$this->form_validation->set_rules('cms_id', 'cms_id', 'required|xss_clean');
			$this->form_validation->set_rules('position','Select Position','required|xss_clean'); 
			if ($this->form_validation->run()) {
				if($this->input->post('url'))
					$url=$this->input->post('url');
				else
					$url=$this->input->post('title');
				$data = array(
						'title'=>trim($this->input->post('title')),
						'slug'=>$url,
						'meta_title'=>trim($this->input->post('meta_title')),
						'meta_keyword'=>trim($this->input->post('meta_keyword')),
						'meta_description'=>trim($this->input->post('meta_description')),
						'description' => trim($this->input->post('cmscontent')),
						'position' => trim($this->input->post('position'))
						
				);
				$this->db->where('id', trim($this->input->post('cms_id')));
				$this->db->update('cms', $data);
				$data['cms']['management'] = $this->admin_cms_model->get_cms();
				$this->session->set_flashdata('message', 'CMS Updated Sucessfully..........');
				redirect('secure/cms');
	
			}else{
	
				$this->template->build('cms/cms_management', $data);
			}
				
		}
	
	}
	
	
}